package com.wfm.leetcode.editor.cn;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;

public class PThree45反转字符串中的元音字母{
//leetcode submit region begin(Prohibit modification and deletion)
class Solution {
    public String reverseVowels(String s) {
        StringBuilder sb = new StringBuilder(s);
        int i = 0;
        int j = s.length()-1;
        Set<Character> set = new HashSet<>();
        set.add('a');
        set.add('e');
        set.add('i');
        set.add('o');
        set.add('u');
        set.add('A');
        set.add('E');
        set.add('I');
        set.add('O');
        set.add('U');
        while (i<j){
            while (i<j&&!set.contains(s.charAt(i))){
                i++;
            }
            while (i<j&&!set.contains(s.charAt(j))){
                j--;
            }
            char tmp = sb.charAt(i);
            sb.setCharAt(i,sb.charAt(j));
            sb.setCharAt(j,tmp);
            i++;
            j--;
        }
        return sb.toString();
    }
}
//leetcode submit region end(Prohibit modification and deletion)

    public static void main(String[] args) { 
        Solution solution = new PThree45反转字符串中的元音字母().new Solution();
        String hello = solution.reverseVowels("hello");
        System.out.println(hello);
        String leetcode = solution.reverseVowels("leetcode");
        System.out.println(leetcode);
    }
}